{extend name="template/base" /}
{block name="content"}
<div style="margin-top:20px;"  class="page-container">
    <div class="toptip">
        <h2>提示：</h2>
        <p>
          选择需要添加试题的科目、专业、知识点，点击选定标签，选择相应的题库、题型，文本框内输入需要增加的题目、试题答案选项（备选项），设定正确答案，填写习题及答案解析<br>
        </p>
    </div>
    <legend><i class="Hui-iconfont">&#xe600;</i>试题管理</legend>
<div class="page-container">
    <form class="form form-horizontal" id="form" method="post" action="{:\\think\\Request::instance()->baseUrl()}">
        <input type="hidden" name="id" value="{$vo.id ?? ''}">
        <div class="row cl">
            <label class="form-label f-l ml-20"><span class="c-red">*</span>知识点：</label>
            <div class="formControls col-xs-8 col-sm-5">
                <textarea style="background-color: #eee;width: 99.7%;"  name="args[q_knowsid]" id="questionknowsid" readonly="" autocomplete="off" cols="106" rows="5" class="form-control" placeholder="" onKeyUp="textarealength(this,100)">{:isset($konws)?$konws['id'].':'.$konws['k_name']:''}</textarea>
            </div>
            <div class="col-xs-offset-4"></div>
        </div>
        <input type="hidden" id="q_subjectid" name="args[q_subjectid]" value="{$vo.q_subjectid??''}">
        <input type="hidden" id="q_sectionid" name="args[q_sectionid]" value="{$vo.q_sectionid??''}">
        <div class="row cl">
        <label class="form-label  f-l ml-20"></label>
            <div class="formControls  col-xs-8 col-sm-5">
                <div class="select-box">
                <select needle="needle" class="select" id="isubjectselect">
                    <option value="0">选择科目</option>
                    {volist name="subject" id="vos"}
                    <option value="{$vos.id}"> {$vos.s_name}</option>
                    {/volist}
                </select>
                </div>
            </div>
            <div class="col-xs-offset-4"></div>
        </div>

    <div class="row cl">
        <label class="form-label  f-l ml-20"></label>
            <div class="formControls  col-xs-8 col-sm-5">
                <div class="select-box">
                <select needle="needle" class="select"  id="isectionselect">
                    <option value="0">选择章节</option>
                </select>
                 </div>
            </div>
        <div class="col-xs-offset-4"></div>
     </div>

    <div class="row cl">
        <label class="form-label  f-l ml-20"></label>
            <div class="formControls  col-xs-8 col-sm-5">
                <div class="select-box">
                <select needle="needle" class="select" id="iknowsselect">
                    <option value="0">选择知识点</option>
                </select>
                 </div>
            </div>
        <div class="col-xs-offset-4"></div>
     </div>

        <div class="row cl">
            <label class="form-label f-l ml-20"></label>
            <div class="col-sm-9 form-inline">
                <input type="button" class="btn btn-primary" value="选定" onclick="javascript:setKnowsList('questionknowsid','iknowsselect','+');setSubSecId();"/>
                <input type="button" class="btn btn-danger" value="清除" onclick="javascript:setKnowsList('questionknowsid','iknowsselect','-');delSubSecId();"/>
            </div>
        </div>
         <div class="row cl">
        <label class="form-label  f-l ml-20">所属题库：</label>
            <div class="formControls  col-xs-8 col-sm-5">
                <div class="select-box">
                <select needle="needle" class="select" datatype="*" msg="您必须为要添加的试题选择一种题型" name="args[q_qbankid]" class="select-default">
                    {volist name="qbank" id="qbanks"}
                    <option value="{$qbanks.id}" {if isset($vo) && $qbanks.id==$vo.q_qbankid}selected{/if}>{$qbanks.name}</option>
                    {/volist}
                </select>
               </div>
            </div>
            <div class="col-xs-offset-4"></div>
        </div>

        <div class="row cl">
        <label class="form-label  f-l ml-20">所属题型：</label>
            <div class="formControls  col-xs-8 col-sm-5">
                <div class="select-box">
                    <select needle="needle" class="select" datatype="*"  msg="您必须为要添加的试题选择一种题型" name="args[q_typeid]" class="select-default" onchange="javascript:setAnswerHtml($(this).find('option:selected').attr('rel'),'q_answerbox');">
                        <option value="">请选择题型</option>
    					{volist name="questypes" id="types"}
                    <!--   <option rel="{if $types['sort']}0{else}{$types.tchoice}{/if}" value="{$types.id}" {if isset($vo) && $types.id==$vo.q_typeid}selected{/if}>{$types.type}</option>-->
					<option rel="{$types.id}" value="{$types.id}" {if isset($vo) && $types.id==$vo.q_typeid}selected{/if}>{$types.type}</option>
                        {/volist}
                    </select>
               </div>
            </div>
            <div class="col-xs-offset-4"></div>
        </div>
		


		<!-- <div class="row cl">
            <label class="form-label  f-l ml-20">所属题型：</label>
			<div class="formControls col-xs-8 col-sm-5 skin-minimal">
				 {volist name="questypes" id="types"}
				<div class="radio-box">
					<input type="radio" rel="{if $types['sort']}0{else}{$types.tchoice}{/if}" id="tchoice-{$types.type}" name="args[q_typeid]" value="{$types.id}" {if isset($vo) && $types.id==$vo.q_typeid}checked="checked"{/if}} datatype="*" nullmsg="您必须为要添加的试题选择一种题型" onclick="javascript:setAnswerHtml($(this).find('option:selected').attr('rel'),'q_answerbox');">
					<label for="tchoice-{$types.type}">{$types.type}</label>
				</div>	
				{/volist}		
            </div>
            <div class="col-xs-offset-4"></div>
        </div> -->
		
        <div class="row cl">
            <label class="form-label f-l ml-20">题干(题目)：</label>
            <div class="formControls  col-xs-8 col-sm-5">
                <textarea class="ckeditor" name="args[q_question]" id="question" style="width:100%;height:300px;">{if isset($vo)}{$vo.q_question}{/if}</textarea>
                <span class="help-block">需要填空处请以()表示。</span>
            </div>
        </div>
        <div class="row cl" id="selecttext">
            <label class="form-label f-l ml-20">备选项：</label>
            <div class="formControls  col-xs-8 col-sm-5">
                <textarea id="questionselect" name="args[q_select]" type="text/plain" style="width:100%;height:300px;">{if isset($vo)}{$vo.q_select}{/if}</textarea>
                <span class="help-block">标准格式（不知道格式请复制）:A. 这是答案    B. 这不是答案    C. 这还是答案    D. 这好像不是答案</span>
            </div>
        </div>

        <!--<div class="row cl" id="selecttext">-->
        <!--<label class="form-label f-l ml-20">备选项：</label>-->
        <!--<div class="col-sm-10">-->
        <!--<textarea class="textarea" name="args[questionselect]" id="questionselect">{x2;$question['questionselect']}</textarea>-->
        <!--&lt;!&ndash;<span class="help-block">无选择项的请不要填写，如填空题、问答题等主观题。</span>&ndash;&gt;-->
        <!--</div>-->
        <!--</div>-->
        <div class="row cl" id="selectnumber">
        <label class="form-label  f-l ml-20">备选项数量：</label>
            <div class="formControls  col-xs-8 col-sm-5">
                <div class="select-box">
                <select class="select" datatype="*" name="args[q_selectnumber]">
                    <option value="0" {if isset($vo) && $vo['q_selectnumber']==0} selected{/if}>0</option>
                    <option value="2" {if isset($vo) && $vo['q_selectnumber']==2} selected{/if}>2</option>
                    <option value="4" {if isset($vo) && $vo['q_selectnumber']==4} selected{/if}>4</option>
                    <option value="5" {if isset($vo) && $vo['q_selectnumber']==5} selected{/if}>5</option>
                    <option value="6" {if isset($vo) && $vo['q_selectnumber']==6} selected{/if}>6</option>
                </select>
               </div>
            </div>
            <div class="col-xs-offset-4"></div>
        </div>
        
     <!-- 临时处理 --><div class="row cl">
            <label class="form-label f-l ml-20">参考答案：</label>
            <div class="col-sm-9 form-inline">
                <div id="q_answerbox_1" class="q_answerbox" {if isset($vo) && $vo.q_typeid!=1}style="display:none;"{/if}>
                    <label class="radio-inline">
                        <input type="radio" name="targs[q_answer1]" value="A" {if isset($vo) && $vo.q_answer == 'A'} checked{/if}>A
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="targs[q_answer1]" value="B"{if isset($vo) && $vo.q_answer == 'B'} checked{/if}>B
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="targs[q_answer1]" value="C"{if isset($vo) && $vo.q_answer == 'C'} checked{/if}>C
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="targs[q_answer1]" value="D"{if isset($vo) && $vo.q_answer == 'D'} checked{/if}>D
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="targs[q_answer1]" value="E"{if isset($vo) && $vo.q_answer == 'E'} checked{/if}>E
                    </label>
                </div>
                 <div id="q_answerbox_2" {if isset($vo) && $vo.q_typeid==2}{else}style="display:none;"{/if} class="q_answerbox">
                    <label class="checkbox-inline">
                        <input type="checkbox" name="targs[q_answer2][]" value="A"{if isset($vo) && in_strpos('A',$vo.q_answer)} checked{/if}>A
                    </label>
                    <label class="checkbox-inline">
                        <input type="checkbox" name="targs[q_answer2][]" value="B"{if isset($vo) && in_strpos('B',$vo.q_answer)} checked{/if}>B
                    </label>
                    <label class="checkbox-inline">
                        <input type="checkbox" name="targs[q_answer2][]" value="C"{if isset($vo) && in_strpos('C',$vo.q_answer)} checked{/if}>C
                    </label>
                    <label class="checkbox-inline">
                        <input type="checkbox" name="targs[q_answer2][]" value="D"{if isset($vo) && in_strpos('D',$vo.q_answer)} checked{/if}>D
                    </label>
                    <label class="checkbox-inline">
                        <input type="checkbox" name="targs[q_answer2][]" value="E"{if isset($vo) && in_strpos('E',$vo.q_answer)} checked{/if}>E
                    </label>
                </div>
                <div id="q_answerbox_3" {if isset($vo) && $vo.q_typeid==3}{else}style="display:none;"{/if} class="q_answerbox">
                    <label class="checkbox-inline">
                        <input type="checkbox" name="targs[q_answer3][]" value="A"{if isset($vo) && $vo.q_answer == 'A'} checked{/if}>A
                    </label>
                    <label class="checkbox-inline">
                        <input type="checkbox" name="targs[q_answer3][]" value="B"{if isset($vo) && $vo.q_answer == 'B'} checked{/if}>B
                    </label>
                    <label class="checkbox-inline">
                        <input type="checkbox" name="targs[q_answer3][]" value="C"{if isset($vo) && $vo.q_answer == 'C'} checked{/if}>C
                    </label>
                    <label class="checkbox-inline">
                        <input type="checkbox" name="targs[q_answer3][]" value="D"{if isset($vo) && $vo.q_answer == 'D'} checked{/if}>D
                    </label>
                    <label class="checkbox-inline">
                        <input type="checkbox" name="targs[q_answer3][]" value="E"{if isset($vo) && $vo.q_answer == 'E'} checked{/if}>E
                    </label>
                </div>
                <div id="q_answerbox_4" class="q_answerbox" {if isset($vo) && $vo.q_typeid==4}{else}style="display:none;"{/if} >
                    <label class="radio-inline">
                        <input type="radio" name="targs[q_answer4]" value="A" {if isset($vo) && $vo.q_answer == 'A'} checked{/if}>对
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="targs[q_answer4]" value="B"{if isset($vo) && $vo.q_answer == 'B'} checked{/if}>错
                    </label>
                </div>
                <div id="q_answerbox_5" class="q_answerbox" style="display:none;">
                    <input type="text" name="targs[q_answer5]" value="{if isset($vo)} {$vo.q_answer}{/if}" />
                </div>
				 <div id="q_answerbox_10" class="q_answerbox" style="display:none;">
                    <input type="text" name="targs[q_answer10]" value="{if isset($vo)} {$vo.q_answer}{/if}" />
                </div>
                <div id="q_answerbox_0" style="display:none;" class="q_answerbox">
                    <textarea class="ckeditor" id="q_answer0" name="targs[q_answer0]" style="width:100%;height:300px;" >{if isset($vo)}{$vo.q_answer}{/if}</textarea>
                </div>
            </div>
        </div>

		


         <!--<div class="row cl">-->
            <!--<label class="form-label  f-l ml-20">参考答案：</label>-->
            <!--<div class="formControls col-xs-8 col-sm-5 skin-minimal">-->


                <!--<div class="radio-box">-->
                    <!--<input type="radio" name="status" id="status-4" value="4" datatype="*" nullmsg="请填写状态">-->
                    <!--<label for="status-1">A</label>-->
                <!--</div>-->
                <!---->
                <!--<div class="radio-box">-->
                    <!--<input type="radio" name="status" id="status-3" value="3" datatype="*" nullmsg="请填写状态">-->
                    <!--<label for="status-1">B</label>-->
                <!--</div>-->


                <!--<div class="radio-box">-->
                    <!--<input type="radio" name="status" id="status-2" value="2" datatype="*" nullmsg="请填写状态">-->
                    <!--<label for="status-1">C</label>-->
                <!--</div>-->


                <!--<div class="radio-box">-->
                    <!--<input type="radio" name="status" id="status-1" value="1" datatype="*" nullmsg="请填写状态">-->
                    <!--<label for="status-1">D</label>-->
                <!--</div>-->
                <!--<div class="radio-box">-->
                    <!--<input type="radio" name="status" id="status-0" value="0" datatype="*" nullmsg="请填写状态">-->
                    <!--<label for="status-0">E</label>-->
                <!--</div>-->
            <!--</div>-->
            <!--<div class="col-xs-offset-4"></div>-->
        <!--</div>-->
		
		
		<!--临时处理-->
        <div class="row cl">
            <label class="form-label f-l ml-20">习题解析：</label>
            <div class="formControls  col-xs-8 col-sm-5">
                <textarea class="ckeditor" name="args[q_describe]" id="questiondescribe" style="width:100%;height:300px;">{if isset($vo)}{$vo.q_describe}{/if}</textarea>
            </div>
        </div>
        <div class="row cl">
        <label class="form-label  f-l ml-20">所属题型：</label>
            <div class="formControls  col-xs-8 col-sm-5">
                <div class="select-box">
                <select name="args[q_level]" class="select" datatype="*" needle="needle" msg="您必须为要添加的试题设置一个难度">
                    <option value="1"{if isset($vo) && $vo['q_level']==1} selected{/if}>易</option>
                    <option value="2"{if isset($vo) && $vo['q_level']==2} selected{/if}>中</option>
                    <option value="3"{if isset($vo) && $vo['q_level']==3} selected{/if}>难</option>
                </select>
               </div>
            </div>
            <div class="col-xs-offset-4"></div>
        </div>
       <div class="row cl">
            <div class="ml-save">
                <button type="submit" class="btn btn-primary radius">&nbsp;&nbsp;保存&nbsp;&nbsp;</button>
                <button type="button" class="btn btn-default radius ml-20" onClick="layer_close();">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>
</div>

{/block}
{block name="script"}
<script type="text/javascript" src="__LIB__/showdown/1.4.2/showdown.min.js"></script>
<script>window.UEDITOR_HOME_URL = '__LIB__/ueditor/1.4.3/'</script>
<script type="text/javascript" charset="utf-8" src="__LIB__/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__LIB__/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="__LIB__/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script>
    $(function () {
        var ue = UE.getEditor('editor',{
            serverUrl:'{:\\think\\Url::build("Ueditor/index")}'
        });
        var converter = new showdown.Converter(),
                text      = $("#markdown_tpl").html();
        $("#markdown").html(converter.makeHtml(text));
    })
</script>
<script type="text/javascript" src="__LIB__/Validform/5.3.2/Validform.min.js"></script>
<script>
    $(function () {
        $("[name='status'][value='{$vo.status ?? '1'}']").attr("checked", true);

        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        $("#form").Validform({
            tiptype: 2,
            ajaxPost: true,
            showAllError: true,
            callback: function (ret) {
                ajax_progress(ret);
            }
        });
    })
</script>
<script>
    $('#isubjectselect').change(function(){
        if(this.value==''){
            return;
        }
        var html='<option value="">选择分类</option>';
        $.post('{:\\think\\Url::build("section")}',{pid:this.value},
                function(data,textStatus){
                    console.log(data);
                    if(data){
                        //$('#lthree').hide();
                        $('#isectionselect').empty();//清空原有的数据
                        var tbody = "";
                        $.each(JSON.parse(data.data), function(i,n){
                            var trs = "";
                            trs += "<option value='" + n.id + "'>" + n.se_name + "</option>";
                            tbody += trs;
                        });
                        tbody=html+tbody;
                        $("#isectionselect").append(tbody);
                    }else{
                        layer.msg('没有子级了!');
                    }
                },'json');
    });
    $('#isectionselect').change(function(){
        if(this.value==''){
            return;
        }
        var html='<option value="">选择分类</option>';
        $.post('{:\\think\\Url::build("knows")}',{pid:this.value},
                function(data,textStatus){

                    if(data){
                        //$('#lthree').hide();
                        $('#iknowsselect').empty();//清空原有的数据
                        var tbody = "";
                        console.log(data.data);
                        $.each(JSON.parse(data.data), function(i,n){
                            console.log(n);
                            var trs = "";
                            trs += "<option value='" + n .id + "'>" + n .k_name + "</option>";
                            tbody += trs;
                        });
                        tbody=html+tbody;
                        $("#iknowsselect").append(tbody);
                    }else{
                        layer.msg('没有子级了!');
                    }
                },'json');
    });
    $('#iknowsselect').change(function(){
        if(this.value==''){
            return;
        }
    });
    function setSubSecId() {
        $('#q_subjectid').val($('#isubjectselect').val());
        $('#q_sectionid').val($('#isectionselect').val());
    }
    function delSubSecId() {
        $('#q_subjectid').val();
        $('#q_sectionid').val();
    }
    function setKnowsList(o,c,t){
        var oo = $('#'+o);
        var oc = $('#'+c);
        if(t == '+')
        {
            if(oc.val() == '' || oc.val() < 1)return false;
            var txt = oc.val()+':'+oc.find("option:selected").text();
            if(oo.val().indexOf(txt) == -1)
            {
                if(oo.val() == '')oo.val(txt);
                else oo.val(txt+'\n'+oo.val());
            }
        }
        else oo.val('');
    }
	
	 function setAnswerHtml(t,o)
    {
	
        $("."+o).hide();
        $("#"+o+"_"+t).show();
        if(parseInt(t) == 0 || parseInt(t) == 5)
        {

            $("#selectnumber").hide();
            $("#selecttext").hide();
        }
        else if(parseInt(t) == 1 || parseInt(t) == 2){
           // $(".select").val(4);
            $("#selectnumber").show();
            $("#selecttext").show();
        }
        else
        {
            //$(".select").val(2);
            $("#selectnumber").show();
            $("#selecttext").show();
        }
    }
  
    $(function(){
        var ue = UE.getEditor('questionselect',{
            toolbars: [
                ['fullscreen', 'source', 'undo', 'redo'],
                ['bold', 'italic', 'underline',  'fontfamily',   'fontsize',  'paragraph', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc']
            ],
            autoHeightEnabled: true,
            autoFloatEnabled: true
        });
        var ue = UE.getEditor('question',{
            toolbars: [
                ['fullscreen', 'source', 'undo', 'redo'],
                ['bold', 'italic', 'underline',  'fontfamily',   'fontsize',  'paragraph', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc']
            ],
            autoHeightEnabled: true,
            autoFloatEnabled: true
        });
        var ue = UE.getEditor('questiondescribe',{
            toolbars: [
                ['fullscreen', 'source', 'undo', 'redo'],
                ['bold', 'italic', 'underline',  'fontfamily',   'fontsize',  'paragraph', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc']
            ],
            autoHeightEnabled: true,
            autoFloatEnabled: true
        });
        var ue = UE.getEditor('q_answer0',{
            toolbars: [
                ['fullscreen', 'source', 'undo', 'redo'],
                ['bold', 'italic', 'underline',  'fontfamily',   'fontsize',  'paragraph', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc']
            ],
            autoHeightEnabled: true,
            autoFloatEnabled: true
        });
    });

</script>
{/block}